﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Settlements.VillageType
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using System.Linq;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Settlements
{
  public sealed class VillageType : MBObjectBase
  {
    private MBList<(ItemObject, float)> _productions;
    public TextObject ShortName;
    public string MeshName;
    public string MeshNameUnderConstruction;
    public string MeshNameBurned;

    internal static void AutoGeneratedStaticCollectObjectsVillageType(
      object o,
      List<object> collectedObjects)
    {
      ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    public static MBReadOnlyList<VillageType> All => Campaign.Current.AllVillageTypes;

    public MBReadOnlyList<(ItemObject, float)> Productions
    {
      get => (MBReadOnlyList<(ItemObject, float)>) this._productions;
    }

    public ItemObject PrimaryProduction
    {
      get
      {
        (ItemObject, float) valueTuple = this._productions[0];
        float num = 0.0f;
        foreach ((ItemObject, float) production in (List<(ItemObject, float)>) this._productions)
        {
          if ((double) production.Item2 * (double) production.Item1.Value > (double) num)
          {
            valueTuple = production;
            num = production.Item2 * (float) production.Item1.Value;
          }
        }
        return valueTuple.Item1;
      }
    }

    public VillageType(string stringId)
      : base(stringId)
    {
    }

    public VillageType Initialize(
      TextObject shortName,
      string meshName,
      string meshNameUnderConstruction,
      string meshNameBurned,
      (ItemObject, float)[] productions)
    {
      this.ShortName = shortName;
      this.MeshName = meshName;
      this.MeshNameUnderConstruction = meshNameUnderConstruction;
      this.MeshNameBurned = meshNameBurned;
      this._productions = productions.ToMBList<(ItemObject, float)>();
      this.AfterInitialized();
      return this;
    }

    public override string ToString() => this.ShortName.ToString();

    public void AddProductions(IEnumerable<(ItemObject, float)> productions)
    {
      this._productions = productions.Concat<(ItemObject, float)>((IEnumerable<(ItemObject, float)>) this._productions).ToMBList<(ItemObject, float)>();
    }

    public float GetProductionPerDay(ItemObject item)
    {
      foreach ((ItemObject, float) production in (List<(ItemObject, float)>) this._productions)
      {
        if (production.Item1 == item)
          return production.Item2;
      }
      return 0.0f;
    }

    public float GetProductionPerDay(ItemCategory itemCategory)
    {
      float productionPerDay = 0.0f;
      foreach ((ItemObject, float) production in (List<(ItemObject, float)>) this._productions)
      {
        if (production.Item1 != null && production.Item1.ItemCategory == itemCategory)
          productionPerDay += production.Item2;
      }
      return productionPerDay;
    }
  }
}
